<template>
  <div class="mv-content">
    <div class="mv-wrap">
      <h3 class="title">mv详情</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video controls :src="mvUrl" autoplay preload="auto"></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class='avatar-wrap'>
            <img :src="artistCover" alt="" />
          </div>
          <span class="name" style="text-align:left;">{{ artistName }}</span>
        </div>
        <div class="mv-info">
          <h4 class="title">{{ mvName }}</h4>
          <span class="date">发布：{{ publishTime }}</span>
          <span class="number">播放：{{ playCount | formatCount }}次</span>
          <p class="desc">{{ desc }}</p>
        </div>
      </div>
      <!-- 热门评论 -->
      <div v-if="hotComments.length != 0" class="comment-wrap">
        <p class="title">
          热门评论<span class="number">({{ hotComments.length }})</span>
        </p>
        <div
          class="comments-wrap"
          v-for="item in hotComments"
          :key="item.commentId"
        >
          <div class="item">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{ item.user.nickname }}：</span>
                <span class="comment">{{ item.content }}</span>
              </div>
              <div v-if="item.beReplied.length != 0" class="re-content">
                <span class="name"
                  >{{ item.beReplied[0].user.nickname }}：</span
                >
                <span class="comment">{{ item.beReplied[0].content }}</span>
              </div>
              <div class="date">{{ item.time | formatTime }}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap" v-if="comments.length != 0">
        <p class="title">
          最新评论<span class="number">({{ total }})</span>
        </p>
        <div class="comments-wrap">
          <div class="item" v-for="item in comments" :key="item.commentId">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{ item.user.nickname }}：</span>
                <span class="comment">{{ item.content }}</span>
              </div>
              <div v-if="item.beReplied.length != 0" class="re-content">
                <span class="name"
                  >{{ item.beReplied[0].user.nickname }}：</span
                >
                <span class="comment">{{ item.beReplied[0].content }}</span>
              </div>
              <div class="date">{{ item.time | formatTime }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mvUrl, simiMV, mvComments, mvDetail, artistInfo } from '@/api/mv'
export default {
  name: 'mvIndex',
  components: {},
  props: {},
  data () {
    return {
      // mv地址
      mvUrl: '',
      simiMV: [],
      // 热门评论
      hotComments: [],
      // 普通评论
      comments: [],
      // mv的名字
      mvName: '',
      // 播放次数
      playCount: '',
      // 发布时间
      publishTime: '',
      // 描述
      desc: '',
      // 歌手名
      artistName: '',
      // 封面
      artistCover: '',
      id: 0
    }
  },
  computed: {},
  watch: {
    id () {
      this.getInfo()
    }
  },
  created () {
    this.id = this.$route.params.id
    this.getInfo()
  },
  mounted () {},
  methods: {
    // 获取评论
    getComments () {
      const { id } = this.$route.params
      mvComments(id, 56, 5).then(res => {
        if (res.data.hotComments) {
          this.hotComments = res.data.hotComments
        }
        this.comments = res.data.comments
        this.total = res.data.total
      })
    },
    // 获取信息
    getInfo () {
      // const { id } = this.$route.params
      mvUrl(this.id).then(res => {
        this.mvUrl = res.data.data.url
      })
      simiMV(this.id).then(res => {
        this.simiMV = res.data.mvs
      })
      // 获取评论
      this.getComments()
      // 获取MV详情
      mvDetail(this.id).then(res => {
        this.mvName = res.data.data.name
        this.playCount = res.data.data.playCount
        this.publishTime = res.data.data.publishTime
        this.desc = res.data.data.desc
        artistInfo(res.data.data.artistId).then(res => {
          // 歌手名
          this.artistName = res.data.artist.name
          this.artistCover = res.data.artist.picUrl
        })
      })
    }
  }
}
</script>

<style scoped lang="less">
.mv-content {
  display: flex;
  .mv-wrap {
    width: 70%;
    margin-right: 35px;
    .date {
      margin-right: 25px;
    }
    .date,
    .number {
      color: #bebebe;
      font-size: 12px;
    }
    .video-wrap {
      float: left;
      width: 336px;
      height: 200px;
      margin: 20px;
      video {
        border-radius: 5px;
        width: 100%;
        outline: none;
      }
    }
    .info-wrap {
      .singer-info {
        float: left;
        margin: 0 20px;
        .avatar-wrap {
          width: 40px;
          height: 40px;
          border-radius: 50%;
          margin: 0 auto;
          margin-bottom: 8px;
          overflow: hidden;
          img{
            height: 100%;
          }
        }
      }
      .mv-info {
        width: 360px;
        .title {
          font-size: 14px;
          overflow:hidden;
          text-overflow:ellipsis;
          white-space:nowrap;
        }
        .desc {
          font-size: 14px;
        }
      }
    }
    .comment-wrap {
      .title {
        margin-top: 24px;
        font-size: 16px;
        .number {
          color: black;
          font-size: 12px;
        }
      }
      .item {
        display: flex;
        padding-top: 20px;
        .icon-wrap {
          margin-right: 15px;
          img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
          }
        }
        &:not(:last-child) {
          .content-wrap {
            border-bottom: 1px solid #f2f2f1;
          }
        }

        .content-wrap {
          padding-bottom: 20px;
          .name {
            color: #517eaf;
            font-size: 14px;
          }
          .comment {
            font-size: 14px;
          }
          .content,
          .re-content {
            margin-bottom: 10px;
          }
          .re-content {
            padding: 10px;
            background-color: #e6e5e6;
            border-radius: 5px;
          }
        }
      }
    }
  }
}
</style>
